/*
 * 邀请收益
 * page邀请收益
 */
import 'package:flutter/material.dart';
import 'package:qgchat/bloc/blocProvider.dart';
import 'package:qgchat/bloc/my/inviteProfitBloc.dart';
import 'package:qgchat/common/class/date/index.dart';
import 'package:qgchat/common/global/global.dart';
import 'package:qgchat/http/models/intodetailsModel.dart';
import 'package:qgchat/widgets/noData.dart';

class InviteProfit extends StatefulWidget {
  InviteProfit({Key key}) : super(key: key);

  @override
  InviteProfitState createState() => InviteProfitState();
}

class InviteProfitState extends State<InviteProfit> {
  InviteProfitBloc bloc;

  @override
  Widget build(BuildContext context) {
    bloc = BlocProvider.of<InviteProfitBloc>(context);
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(px(88)),
        child: AppBar(
          centerTitle: true,
          title: Text(
            "邀请收益",
            style: TextStyle(
              color: Colors.black,
              fontSize: px(34),
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
      ),
      body: bodyHandle(),
    );
  }

  // 生成body
  Widget bodyHandle() {
    return Container(
      color: Colors.white,
      child: StreamBuilder(
        stream: bloc.invStream,
        builder: (BuildContext context, AsyncSnapshot snapshot) {
          if (snapshot.hasData) {
            if (snapshot.data.isNotEmpty) {
              List<IntodetailsModel> list = snapshot.data;
              return ListView(
                children: list.map<Widget>((item) {
                  return inviteInfoHandle(item);
                }).toList(),
              );
            } else {
              return NoData("暂无邀请收益");
            }
          } else {
            return Container();
          }
        },
      ),
    );
  }

  // 单个详情
  Widget inviteInfoHandle(IntodetailsModel item) {
    return Container(
      height: px(175),
      padding: EdgeInsets.symmetric(horizontal: px(30)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(top: px(30)),
            child: ClipOval(
              child: Image.network(
                "${item.memberHead}",
                width: px(54),
                height: px(54),
                fit: BoxFit.cover,
              ),
            ),
          ),
          Container(
            width: px(600),
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(
                  width: 1,
                  color: col("edeff2"),
                ),
              ),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Container(
                  margin: EdgeInsets.only(top: px(30)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Text(
                        "${item.memberNickname}",
                        style: TextStyle(
                          color: col("303133"),
                          fontSize: px(28),
                        ),
                      ),
                      Text(
                        "+${item.money}元",
                        style: TextStyle(
                          color: col("303133"),
                          fontSize: px(40),
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  child: Text(
                    "充值: ￥${item.gold}",
                    style: TextStyle(
                      color: col("303133"),
                      fontSize: px(26),
                    ),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: px(5)),
                  child: Text(
                    "${Date.simple(int.parse(item.createtime))}",
                    style: TextStyle(
                      color: col("909399"),
                      fontSize: px(24),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
